package day7;

import java.util.*;

public class TestTreeSet {
    public static void main(String[] args) {
        //1.数字的TreeSet:默认按照升序
        Set<Integer> set1 = new TreeSet<>(Arrays.asList(3,7,9,11,15,11,3));
        System.out.println(set1);

        //2.String类：按位比较ASCII
        Set<String> set2 = new TreeSet<>(Arrays.asList("aa","bb","abc","1a"));
        Set<String> set3 =new TreeSet<>((s1,s2)->s2.compareTo(s1));
        set3.addAll(set2);
        System.out.println(set3);

        //3.对象类排序：斗地主针对于牌对象排序
        //♥10  ♠J ♣3 ♦10 🃏
        //🃏 ♠J  ♥10 ♦10 ♣3

//        Integer[] nums = {1,2,1,7,10};
//        List<Integer> list = Arrays.asList(nums);
//        System.out.println(list.get(2));
//        //list.add(100); 不能修改，不支持的异常
        Set<Card> set4 = new TreeSet<>((c1,c2)->{
            int i =c2.num-c1.num;//降序排序
            if (i == 0) i=c1.str.compareTo(c2.str);//如果数值相同的，再根据花色排序
            return i;
        });
        //定义所有的牌对象 定义存储所有的牌对象
        String[] color = {"♣","♠","♥","♦"};
        String[] nums = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        List<Card> cards = new ArrayList<>();//用来存储所有牌
        for (String s:color){
            for (int i =0;i<nums.length;i++){
                cards.add(new Card(s+nums[i],i+3));
            }
        }
        cards.add(new Card("小🃏",16));
        cards.add(new Card("大🃏",17));
        System.out.println(cards);
        //Collections.shuffle(cards);//打乱顺序
        Random r = new Random();
        for (int i = 0; i < 10; i++) {
            int index = r.nextInt(cards.size());
            set4.add(cards.get(index));
        }
        System.out.println(set4);
    }
}
class Card{
    String str;//存储内容 ♣10
    int num;//存储牌对应的数值

    public Card(String str, int num) {
        this.str = str;
        this.num = num;
    }

    @Override
    public String toString() {
        return str;
    }

}
